#!/bin/bash

# Copyright 2014 Treode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build and test a pull request.
#
# This script works with the Jenkins service. Jenkins triggers the build whenever there is a new
# pull request on GitHub, or a change on an existing pull request. Jenkins runs this script, and
# then it marks the pull request with success/failure.
#
# Specifically, this script
# 1) Builds and tests the libraries for the Treode store.
# 2) Publishes those libraries locally.
# 3) Builds and tests the examples using the locally published libraries.

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. $DIR/scripts/build-functions.sh

# Number of seeds for pseudo-random tests.
export NSEEDS=10

clean

#
# Compile.
#

# Compile, and also publish locally for the demos below.
echo-do ${SBT} +test:compile +publish-local

# Movies demo; it has multiple components.
(cd demos/movies; echo-do ${SBT} test:compile); expect-status 0
(cd demos/movies/webui; echo-do ${NPM} install --save); expect-status 0
(cd demos/movies/webui; echo-do ${GRUNT} dist); expect-status 0

#
# Test
#

echo-do ${SBT} test intensive:test

(cd demos/movies; echo-do ${SBT} test); expect-status 0

#
# Done.
#

wrapup
